from django.db import models

# Create your models here.

class Author(models.Model):
    name = models.CharField(max_length=100, verbose_name='作者姓名')
    bio = models.TextField(blank=True, verbose_name='作者简介')

    def __str__(self):
        return self.name

class Book(models.Model):
    title = models.CharField(max_length=200, verbose_name='书名')
    author = models.ForeignKey(Author, on_delete=models.CASCADE, verbose_name='作者')
    published_date = models.DateField(verbose_name='出版日期')
    isbn = models.CharField(max_length=13, unique=True, verbose_name='ISBN')
    summary = models.TextField(blank=True, verbose_name='简介')
    cover = models.ImageField(upload_to='book_covers/', blank=True, null=True, verbose_name='封面', default='default_cover.jpg')

    def __str__(self):
        return self.title
